package com.sensetime.jv.controller;


import com.github.pagehelper.PageInfo;
import com.sensetime.jv.annotation.RequirePermission;
import com.sensetime.jv.entity.ReturnWrapper;
import com.sensetime.jv.service.PermissionService;
import com.sensetime.jv.vo.request.PermissionUrlEditReqVO;
import com.sensetime.jv.vo.response.PermissionRespVO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.ThreadContext;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/url-permission")
@Slf4j
public class UrlPermissionController {


    @Resource
    private PermissionService permissionService;

    @GetMapping("url/list")
    @RequirePermission( description = "查询接口权限")
    public ReturnWrapper<PageInfo<PermissionRespVO>> list(String name,Integer page,Integer size){
        log.info(">>> MDC requestId = {}", ThreadContext.get("requestId"));
        PageInfo<PermissionRespVO> respVO = permissionService.list(name,page,size);
        return ReturnWrapper.success(respVO);
    }


    @DeleteMapping("url/{id}")
    @RequirePermission(description = "删除接口权限")
    public ReturnWrapper<Void> deleteById(@PathVariable Long id){

        permissionService.deleteById(id);
        return ReturnWrapper.success();
    }


    @PutMapping("url/edit")
    @RequirePermission(description = "更新接口权限")
    public ReturnWrapper<Integer> updateById(@Valid @RequestBody PermissionUrlEditReqVO reqVO){

        permissionService.updateById(reqVO);
        return ReturnWrapper.success(reqVO.getId());
    }
}
